﻿@using nwrole.lib
@model nwrole.Orchestrator.site.Models.SupervisorDetailsViewModel

@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Supervisor @Model.SupervisorInfo.DisplayName</h2>

<h3>Services</h3>

<table>
    <tr>
        <th>Name</th>
        <th>Id</th>
        <th>State</th>
        <th>Last registered</th>
    </tr>
    @foreach (var item in Model.ServicesInfo ) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Id)
            </td>
            
            <td>
                @Html.DisplayFor(modelItem => item.State)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LastRegistered)
            </td>
            <td>
                @Html.ActionLink("Details", "Index", "Service", new { id=item.Id }, null)
                @Html.ActionLink("Log", "Show", "Log", new { id=item.Id }, null) 
                @if(item.State == ServiceState.Running)
                {
                    @: | 
                    @Html.ActionLink("Stop", "StopService", new { id = item.Id })
                    @: | 
                    @Html.ActionLink("Restart", "RestartService", new { id = item.Id }) 
                }
                else if(item.State == ServiceState.Stopped || item.State == ServiceState.Deactivated)
                {
                    @: | 
                    @Html.ActionLink("Start", "StartService", new { id = item.Id }) 
                }
                
            </td>
        </tr>
    }
</table>

<p>
    @Html.ActionLink("Back to Supervisor list", "Index", "Supervisor")
</p>
